package com.example.filterdemo.filter;

import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@Component
public class Test2Filter implements Filter {

    // 添加构造函数日志
    public Test2Filter() {
        System.out.println("Test2Filter 实例被创建: " + this.hashCode());
    }

    @Override
    public void init(FilterConfig filterConfig) {
        System.out.println("Test2Filter 初始化: " + filterConfig.getFilterName());
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) servletRequest;
        System.out.println("Test2Filter触发: URI=" + req.getRequestURI() + ", DispatcherType=" + req.getDispatcherType());
        filterChain.doFilter(servletRequest, servletResponse);
    }
}